package reflection;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Test08 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException {
        Class<?> c1 = Class.forName("reflection.User");
        User user = new User();

       /* System.out.println(c1.getName());
        System.out.println(c1.getSimpleName());
        System.out.println(c1.getFields());
        for (Field field : c1.getFields()) {
            System.out.println(field);
        }

        for (Field field : c1.getDeclaredFields()) {
            System.out.println(field);
        }
//        Field name = c1.getField("name");
//        System.out.println(name);
        System.out.println(c1.getDeclaredField("name"));
*/
        Method[] methods = c1.getMethods();
        Field[] declaredFields = c1.getDeclaredFields();
        for (Method method : methods) {
            System.out.println(method);
        }
        for (Field declaredField : declaredFields) {
            System.out.println(declaredField);
        }

        Method[] declaredMethods = c1.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {

            System.out.println(declaredMethod);
        }

        System.out.println(c1.getMethod("getAge",null));
        System.out.println(c1.getMethod("setName", String.class));
        System.out.println(c1.getMethod("setAge", int.class));
        Constructor<?>[] constructors = c1.getConstructors();
        Constructor<?>[] declaredConstructors = c1.getDeclaredConstructors();
        for (Constructor<?> constructor : constructors) {
            System.out.println(constructor);
        }
        for (Constructor<?> declaredConstructor : declaredConstructors) {

            System.out.println(declaredConstructor);
        }
        Constructor<?> declaredConstructor = c1.getDeclaredConstructor(String.class, int.class, int.class);
        System.out.println(declaredConstructor);
        System.out.println(c1.getDeclaredConstructor());

    }
}
